package com.wd.good.service.impl;

import com.wd.good.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * @description: Spring Retry 注解重试
 * @author wangdpng
 * @date 2023/11/18 21:17
 */
@Slf4j
@Service
public class SpringRetryErrorImpl implements CommonService {
    @Override
    @Retryable(maxAttempts = 4,backoff = @Backoff(delay = 2000,multiplier = 2))
    public void doSomething() {
        System.out.println("doSomething");
        //int a = 3/0;
        throw new RuntimeException("doSomething error");
    }
    @Recover // 重试达到指定次数后的处理
    public void recover(RuntimeException e){
        log.error("达到最大重试次数",e);
    }
}
